﻿namespace Pna.Framework
{
    using Appccelerate.Bootstrapper;
    using Castle.Windsor;

    public class PnaBootstrapper
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PnaBootstrapper" /> class.
        /// </summary>
        /// <param name="container">The container.</param>
        public PnaBootstrapper(IWindsorContainer container)
        {
            var extensions = container.ResolveAll<IPnaExtension>();
            using (var bootstrapper = new DefaultBootstrapper<IPnaExtension>())
            {
                var strategy = new PnaStrategy(container);
                bootstrapper.Initialize(strategy);

                foreach (var pnaExtensions in extensions)
                {
                    bootstrapper.AddExtension(pnaExtensions);
                }
                
                bootstrapper.Run();
     
                // When application finished call
     
                bootstrapper.Shutdown();
            }
        } 
    }
}